<?php

//基本栏目模型
class About_model extends Model {

	function About_model()
	{
		parent::Model();	
		$this->load->database();
	}
	
	//更新栏目内容
	function update($content, $type = "about")
	{
		if(!in_array($type, array("about", "contact", "ad", "hr", "partner", "sitemap", "help", "legal"))) $type = "about";
		$query = $this->db->get_where("about", array("type"=>$type));
		if ($query->num_rows()>0) {
			$data = array(
				"content" => $content,
				"addtime" => time(),
			);
			$this->db->where("type", $type);
			$result = $this->db->update("about", $data);
		} else {
			$data = array(
				"type" => $type,
				"content" => $content,
				"addtime" => time(),
			);
			$result = $this->db->insert("about", $data);
		}
		return $result;
	}
	
	//获取内容
	function get($type)
	{
		if(!in_array($type, array("about", "contact", "ad", "hr", "partner", "sitemap", "help", "legal"))) $type = "about";
		$row = array();
		$query = $this->db->from("about")->where("type", $type)->order_by("id", "desc")->limit(1)->get();
		if ($query->num_rows()>0) {
			$row = $query->row_array();
		}
		return $row;
	}
	
}

/* End of file */